package jay.home.bet.test;

import sun.reflect.misc.FieldUtil;
import java.lang.reflect.Field;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.ArrayList;

public class Bean2SqlMapTemplate
{
  protected static String nl;
  public static synchronized Bean2SqlMapTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    Bean2SqlMapTemplate result = new Bean2SqlMapTemplate();
    nl = null;
    return result;
  }

  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "  \tmap.put(\"";
  protected final String TEXT_2 = "\", \"";
  protected final String TEXT_3 = "\");";
  protected final String TEXT_4 = NL + "      map.put(\"";
  protected final String TEXT_5 = ".";
  protected final String TEXT_6 = "\", \"";
  protected final String TEXT_7 = "_";
  protected final String TEXT_8 = "\");";
  protected final String TEXT_9 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
List<String> list = new ArrayList<String>();
Class bean = (Class)argument;
Field[] fields = FieldUtil.getDeclaredFields(bean);
for(Field field : fields)
{
  if(BeanUtils.isPrimitiveWrapper(field.getType()))
  {
  
    stringBuffer.append(TEXT_1);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_3);
    
  }
  else
  {
    Field[] fields2 = FieldUtil.getDeclaredFields(field.getType());
    for(Field item : fields2)
    {
    
    stringBuffer.append(TEXT_4);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(item.getName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(item.getName());
    stringBuffer.append(TEXT_8);
    
	}
  }
}

    stringBuffer.append(TEXT_9);
    return stringBuffer.toString();
  }
}
